﻿#include "CPublicData.h"
#include <QFile>
#include <QDomDocument>
#include <QDebug>
#include <QCoreApplication>
#include <QLibrary>
#include <QDir>
#include "CRollerMgr.h"
#include <quuid.h>
QString createGuid()
{
	// 生成一个新的 UUID
	QUuid uuid = QUuid::createUuid();

	// 将生成的 UUID 转换为二进制数据
	QByteArray uuidBytes = uuid.toRfc4122();

	// 将二进制数据转换为十六进制字符串（无连字符）
	QString uuidString;
	for (int i = 0; i < uuidBytes.size(); ++i)
	{
		uuidString += QString("%1").arg((unsigned char)uuidBytes.at(i), 2, 16, QChar('0'));
	}
	return uuidString;
}

bool CPublicData::initSql()
{
	if (m_pSqlDllOper == nullptr)
	{
		QString sConfigPath = QCoreApplication::applicationDirPath() + "/DLL/roller.xml";
		// 获取当前程序路径
		QString exePath = QCoreApplication::applicationDirPath();
		// 构造 DLL 文件路径
		QString sDllPath = QDir(exePath).filePath("SqlOper.dll");
		m_pSqlDllOper = new CSqlDllOper(g_sTableName, sConfigPath, sDllPath);
	}
	return m_pSqlDllOper->initSql();
}


bool CPublicData::getConfig()
{
	return true;
}

bool CPublicData::saveConfig()
{
	return true;
}


CPublicData::CPublicData()
{
	m_bConfig = false;
	m_pSqlDllOper = nullptr;
	m_bSqlInit = false;
	m_pRollerMgr = nullptr;
	m_pBindWidget = nullptr;
}

CPublicData::~CPublicData()
{
	if (m_pSqlDllOper != nullptr)
	{
		delete m_pSqlDllOper;
		m_pSqlDllOper = nullptr;
	}
}
